
<!-- 线索管理-情报线索信息：签收
 * @Author: zhanbh
 * @Date: 2021-04-13 15:03:58
 * @project: 天津YQ平台
-->
<template>
  <module-tabs class="yq-sign" v-model="activeName" :tabs="tabs" is-flex-box>
    <template #first>
      <sign ref="form" :other-form="otherForm"/>
    </template>
    <template #second>
      <all-info />
    </template>
    <!-- TODO:此版本暂时不出现工作流程图，详情才有 -->
    <!-- <template #thirds> 
      <work-flow />
    </template> -->

    <template #header-btns v-if="activeName === 'first'">
      <dg-button type="primary" size="mini" @click="onSubmit" :loading="loading">提交</dg-button>
      <dg-button size="mini" @click="()=>$router.go(-1)">关闭</dg-button>
    </template>
  </module-tabs>
</template>

<script>
import ModuleTabs from '@/components/layout/module-tabs';
import AllInfo from '@/pages/ExterCommun/detail/components/AllInfo';
import WorkFlow from '@/pages/ExterCommun/detail/components/WorkFlow';
import Sign from "../components/Sign"
import { flowMainSignIn } from '@/api/common';

export default {
  name: 'ImpSign',
  components: {
    ModuleTabs,
    AllInfo,
    Sign,
    WorkFlow
  },
  props: {
    otherForm: {
      type: Function,
      default: (vm) => {
        return () => {
          let textareaAttrs = {
            type: 'textarea',
            rows: 3,
            placeholder: '请输入内容',
            maxlength: '200',
             showWordLimit: true
          };
          return [
            {
              prop: 'cbyj',
              label: '呈报意见',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'xxbs',
              label: '信息报送',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'nxdzl',
              label: '拟下达指令',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'drzsCode',
              label: '当日值守',
              col: 12,

              tag: 'dg-select',
              tagBind: {
                data: vm.jrzs,
                valueName: 'id',
                labelName: 'name',
              }
            },
            {
              prop: 'drzhzCode',
              label: '今日指挥长',
              col: 12,
              tag: 'dg-select',
              tagBind: {
                data: vm.djrzs,
                valueName: 'id',
                labelName: 'name'
              }
            }
          ];
        };
      }
    }
  },
  data() {
    return {
      loading: false,
      tabs: [
        {
          label: '签收',
          name: 'first'
        },
        {
          label: '基本信息',
          name: 'second'
        },
        // {
        //   label: '工作流程图',  //TODO:此版本暂时不出现工作流程图
        //   name: 'thirds'
        // }
        // {
        //   label: '流程图',
        //   name: 'fourth'
        // }
      ],
      activeName: 'first',
   

  
    };
  },
  computed: {
    flowId() {
      return this.$route.params.id;
    },
  },

  methods: {
    onSubmit() {
      let that =this;
      this.$refs.form.$refs.form.validate((valid) => {
        if (valid) {
          that.loading = true;
          const form = Object.assign({},that.$refs.form.form);
          if(that.$refs.form.form.sjqtCode){
             form.sjqtCode = that.$refs.form.form.sjqtCode.join(",");
          }
          if(that.$refs.form.form.xxdtpgCode){
            form.xxdtpgCode = that.$refs.form.form.xxdtpgCode.join(",");
          }
          flowMainSignIn({
            flowId: that.flowId,
            ...form
          })
            .then(() => {
              that.$message.success('操作成功');
              that.$router.go(-1);
              that.loading = false;
            })
            .catch(() => {
              that.$message.warning('操作失败');
              that.loading = false;
            });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.yq-sign {
  height: calc(100vh - 11rem);

  &__group {
    display: flex;
    align-items: center;

    .dg-radio {
      margin-left: 0.5rem;
    }
  }
}
.edit-form {
  max-width: 1000px;
}
</style>
